let App = getApp();
import { CategoryModel } from '../../models/CategoryModel.js'
let category = new CategoryModel()
Page({
  data: {
    goods:{},// 搜索商品数据
    searchValue:'',// 父组件传递子组件(关键词)
    noList: true,// 判断是否有商品(显示)
    // orderBy:'',// 父组件传递子组件(排序)
    // SortPrice:0,// 价格排序

    searchColor: "rgba(0,0,0,0.4)",
    searchSize: "15",
    searchName: "搜索商品",

    scrollHeight: null,
    showView: false,
    arrange: "",

    // 第三次改动
    option: {},
    list: {},

    no_more: false,
    // 改动的地方
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (option) {
    console.log(option)
    let _this = this;
    _this.setData({
      searchValue:option.search
    })

    // 设置商品列表高度
    // _this.setListHeight();

    // 记录option
    // _this.setData({ option}, function () {
    //   // 获取商品列表
    //   _this.getGoodsList(true);
    // });

  },


  signEvent: function(e){
    let goods = e.detail.res
    console.log(goods)
    this.setData({
      goods:goods,
      noList:false
    })
  },

  /**
   * 设置商品列表高度
   */
  setListHeight: function () {
    let _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          scrollHeight: res.windowHeight - 90,
        });
      }
    });
  },



  /**
   * 跳转筛选
   */
  toSynthesize: function (t) {
    wx.navigateTo({
      url: "../category/screen?objectId="
    });
  },

  /**
   * 切换列表显示方式
   */
  onChangeShowState: function () {
    let _this = this;
    _this.setData({
      showView: !_this.data.showView,
      arrange: _this.data.arrange ? "" : "arrange"
    });
  },

  /**
   * 下拉到底加载数据
   */
  bindDownLoad: function () {
    // 已经是最后一页
    if (this.data.page >= this.data.list.last_page) {
      this.setData({ no_more: true });
      return false;
    }
    this.getGoodsList(false, ++this.data.page);
  },

  /**
   * 设置分享内容
   */
  onShareAppMessage: function () {
    return {
      title: "全部分类",
      desc: "",
      path: "/pages/category/index"
    };
  },

});
